import api from './index';

/**
 * 用户登录
 * @param data 
 * @returns 
 */
export const userLoginApi = (data: LoginForm): Promise<ResponseData<UserData>> =>
  api.post('/user/login', data);

/**
 * 更新用户信息
 * @param data 
 * @returns 
 */
export const updateUserInfoApi = (data: UpdateUserInfoForm): Promise<ResponseData<null>> =>
  api.post('/user/update', data);

/**
 * 注册
 */
export const registerApi = (data: RegisterForm): Promise<ResponseData<UserData>> =>
  api.post('/user/register', data);

/**
 * 管理员登录
 */
export const adminLoginApi = (data: LoginForm): Promise<ResponseData<UserData>> =>
  api.post('/user/admin/login', data);

/**
 * 根据用户id查询地址列表
 */
export const getAddressListApi = (id: number): Promise<ResponseData<Address[]>> =>
  api.get('/user/getAddress/' + id);

/**
 * 新增地址
 */
export const addAddressApi = (data: Omit<Address, 'id'>): Promise<ResponseData<null>> =>
  api.post('/user/addAddress', data);

/**
 * 删除地址
 */
export const deleteAddressApi = (id: number): Promise<ResponseData<null>> =>
  api.get('/user/deleteAddress/' + id);


/**
 * 更新地址
 */
export const updateAddressApi = (data: Address): Promise<ResponseData<null>> =>
  api.post('/user/updateAddress', data);


/**
 * 根据用户id查询用户信息
 */
export const getUserInfoApi = (): Promise<ResponseData<any>> =>
  api.get('/user/getUserInfo');

/**
 * 获取用户列表
 */
export const getUserListApi = (): Promise<ResponseData<any>> =>
  api.get('/user/getAll');

/**
 * 删除用户
 */
export const deleteUserApi = (id: number): Promise<ResponseData<null>> =>
  api.get('/user/delete/' + id);


/**
 * 管理员新增用户
 */
export const addUserApi = (data: Omit<UserData['userInfo'], 'id' | 'created_time'>): Promise<ResponseData<null>> =>
  api.post('/user/admin/register', data);

